package sz.szsmk.citizencard.ui.adapter;

import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.alibaba.android.vlayout.DelegateAdapter;
import com.alibaba.android.vlayout.LayoutHelper;
import com.alibaba.android.vlayout.layout.DefaultLayoutHelper;
import sz.szsmk.citizencard.R;
import sz.szsmk.citizencard.databinding.RoutineTwoBinding;
import sz.szsmk.citizencard.model.network.bean.response.QueryUserCardResponse;
import sz.szsmk.citizencard.ui.activity.HomeRoutineCardActivity;

/**
 * Copyright (c)2018
 * author: zdh
 * created on: 2018/7/16 18:48
 * description:
 */
public class RoutineTwoAdapter extends DelegateAdapter.Adapter<RoutineTwoAdapter.RoutineTwoHolder> {
    private HomeRoutineCardActivity mContext;
    private LayoutHelper mDefaultLayoutHelper;
    private QueryUserCardResponse.DataBean whxfData;
    private QueryUserCardResponse.DataBean tyhmData;


    public RoutineTwoAdapter(HomeRoutineCardActivity homeRoutineCardActivity, DefaultLayoutHelper twoHelper) {
        mContext = homeRoutineCardActivity;
        mDefaultLayoutHelper = twoHelper;
    }

    @Override
    public LayoutHelper onCreateLayoutHelper() {
        return mDefaultLayoutHelper;
    }

    @Override
    public int getItemViewType(int position) {
        return R.layout.routine_two;
    }

    @Override
    public RoutineTwoHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return RoutineTwoHolder.creat(parent);
    }

    @Override
    public void onBindViewHolder(RoutineTwoHolder holder, int position) {
        loadItemData(position, holder.binding);
    }

    private void loadItemData(int position, RoutineTwoBinding binding) {
        if (whxfData != null) {
            if (whxfData.getCardState().equals("1")) {
                binding.cardWhxfWkt.setVisibility(View.GONE);
                binding.cardWhxfYkt.setVisibility(View.VISIBLE);
                binding.cardWhxfEndtime.setText(whxfData.getEndTime() + "");
                binding.cardWhxfTimes.setText(whxfData.getSpareTimes() + "次");
            } else {
                binding.cardWhxfWkt.setVisibility(View.VISIBLE);
                binding.cardWhxfYkt.setVisibility(View.GONE);
            }

        }
        if (tyhmData != null) {
            if (whxfData.getCardState().equals("1")) {
                binding.cardTyhmWkt.setVisibility(View.GONE);
                binding.cardTyhmYkt.setVisibility(View.VISIBLE);
                binding.cardTyhmEndtimes.setText(tyhmData.getEndTime() + "");
                binding.cardTyhmTimes.setText(tyhmData.getSpareTimes() + "次");
            } else {
                binding.cardTyhmWkt.setVisibility(View.VISIBLE);
                binding.cardTyhmYkt.setVisibility(View.GONE);
            }

        }
    }

    @Override
    public int getItemCount() {
        return 1;
    }

    public void setWhxfData(QueryUserCardResponse.DataBean whxfData) {
        this.whxfData = whxfData;
    }

    public void setTyhmData(QueryUserCardResponse.DataBean tyhmData) {
        this.tyhmData = tyhmData;
    }

    public static class RoutineTwoHolder extends RecyclerView.ViewHolder {

        private RoutineTwoBinding binding;

        public static RoutineTwoHolder creat(ViewGroup parent) {
            RoutineTwoBinding binding = RoutineTwoBinding
                    .inflate(LayoutInflater.from(parent.getContext()), parent, false);
            return new RoutineTwoHolder(binding);
        }

        public RoutineTwoHolder(RoutineTwoBinding binding) {
            super(binding.getRoot());
            this.binding = binding;
        }
    }
}
